package spring.cloud.tasks.common.node;

public class ExecutorNodePath {


    public static final String EXECUTORS_NODE_PATH = "/executors";

    public static final String EXECUTOR_NODE_PATH = EXECUTORS_NODE_PATH + "/%s";
    //
    public static final String EXECUTOR_PROCESS_SUCCESS_COUNT = EXECUTOR_NODE_PATH + "/process_success_count";
    public static final String EXECUTOR_PROCESS_FAILURE_COUNT = EXECUTOR_NODE_PATH + "/process_failure_count";
    //
    public static final String EXECUTOR_RUN_ONE_TIME = EXECUTOR_NODE_PATH + "/run_one_time";
    public static final String EXECUTOR_STOP_ONE_TIME = EXECUTOR_NODE_PATH + "/stop_one_time";
    public static final String EXECUTOR_IP = EXECUTORS_NODE_PATH + "/%s/ip";
    public static final String EXECUTOR_STATUS = EXECUTORS_NODE_PATH + "/%s/status";

    private ExecutorNodePath() {
    }


    public static String getExecutorsNodePath() {
        return EXECUTORS_NODE_PATH;
    }

    public static String getExecutorsNodePath(final String executorId) {
        return EXECUTORS_NODE_PATH + "/" + executorId;
    }

    public static String getExecutorsNodePath(final String executorId, final String nodeName) {
        return EXECUTORS_NODE_PATH + "/" + executorId + "/" + nodeName;
    }

    public static String getExecutorOwnTrafficNodePath(final String executorId) {
        return getExecutorsNodePath(executorId, "ownTraffic");
    }

    public static String getExecutorIpNodePath(final String executorName) {
        return getExecutorsNodePath(executorName, "ip");
    }

    public static String getExecutorRestartNodePath(final String executorName) {
        return getExecutorsNodePath(executorName, "restart");
    }

    public static String getProcessSuccessCountNode(String executorId) {
        return String.format(EXECUTOR_PROCESS_SUCCESS_COUNT, executorId);
    }

    public static String getProcessFailureCountNode(String executorId) {
        return String.format(EXECUTOR_PROCESS_FAILURE_COUNT, executorId);
    }

    public static String getRunOneTimePath(String executorId) {
        return String.format(EXECUTOR_RUN_ONE_TIME, executorId);
    }

    public static String getStopOneTimePath(String executorId) {
        return String.format(EXECUTOR_STOP_ONE_TIME, executorId);
    }


    public static boolean isRunOneTimePath(final String taskId, String path, String executorId) {
        return path.startsWith(TaskNodePath.getRunOneTimePath(taskId));
    }

    public static boolean isStopOneTimePath(final String taskId, String path, String executorId) {
        return path.startsWith(TaskNodePath.getStopOneTimePath(taskId));
    }

}
